//
//  HomeViewController.m
//  MRBang
//
//  Created by 铅笔 on 15/12/14.
//  Copyright © 2015年 杭州易网新科技. All rights reserved.
//

#import "HomeViewController.h"
#import "HelpMeDoHomeVC.h"//帮我办
#import "HelpMeBagHomeVC.h"//帮我贷

@interface HomeViewController ()

@property (nonatomic,strong) UIButton *button_first;

@property (nonatomic,strong) UIButton *button_second;
@property (nonatomic,strong) UIButton *button_three;
@property (nonatomic,strong) UIButton *button_four;

@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = COLOR_EVERYVIEWBG;
    
//    手势问题
    UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipe)];
    swipe.direction = UISwipeGestureRecognizerDirectionRight;
    [self.view addGestureRecognizer:swipe];
    
    UISwipeGestureRecognizer *toleftswipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipe)];
    toleftswipe.direction = UISwipeGestureRecognizerDirectionLeft;
    [self.view addGestureRecognizer:toleftswipe];
}

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBarHidden = YES;
    self.tabBarController.tabBar.hidden = NO;
    
    [self initWithAllSubviews];
}

#pragma mark -- 创建视图
- (void)initWithAllSubviews
{
    CGFloat buttonW = (kScreenWidth-30)/2;
    CGFloat buttonH = (kScreenHeight-20-60-45)/2;
    
    CGFloat marggin = 20;
    
    self.button_first = [[UIButton alloc] initWithFrame:CGRectMake(10, marggin+20, buttonW, buttonH)];
    [self.view addSubview:self.button_first];
    [self.button_first setBackgroundImage:[UIImage imageNamed:@"home_4"] forState:UIControlStateNormal];
    self.button_first.tag = 10;
    [self.button_first addTarget:self action:@selector(enterIntoDifferentBlock:) forControlEvents:UIControlEventTouchUpInside];
    
    self.button_second = [[UIButton alloc] initWithFrame:CGRectMake(10*2+buttonW, marggin+20, buttonW, buttonH)];
    [self.view addSubview:self.button_second];
    [self.button_second setBackgroundImage:[UIImage imageNamed:@"home_1"] forState:UIControlStateNormal];
    self.button_second.tag = 11;
    [self.button_second addTarget:self action:@selector(enterIntoDifferentBlock:) forControlEvents:UIControlEventTouchUpInside];
    
    self.button_three = [[UIButton alloc] initWithFrame:CGRectMake(10, marggin*2+buttonH+20, buttonW, buttonH)];
    [self.view addSubview:self.button_three];
    [self.button_three setBackgroundImage:[UIImage imageNamed:@"home_3"] forState:UIControlStateNormal];
    self.button_three.tag = 12;
    [self.button_three addTarget:self action:@selector(enterIntoDifferentBlock:) forControlEvents:UIControlEventTouchUpInside];
    
    self.button_four = [[UIButton alloc] initWithFrame:CGRectMake(10*2+buttonW,marggin*2+buttonH+20, buttonW, buttonH)];
    [self.view addSubview:self.button_four];
    [self.button_four setBackgroundImage:[UIImage imageNamed:@"home_2"] forState:UIControlStateNormal];
    self.button_four.tag = 13;
    [self.button_four addTarget:self action:@selector(enterIntoDifferentBlock:) forControlEvents:UIControlEventTouchUpInside];

}

#pragma mark --- 点击进入 不同的 模块
- (void)enterIntoDifferentBlock:(UIButton *)sender
{
    if (sender.tag==10) {
//        [self.tabBarController setSelectedIndex:2];
        HelpMeDoHomeVC *meDoneView = [[HelpMeDoHomeVC alloc] init];
        [self.navigationController pushViewController:meDoneView animated:YES];
    }
    if (sender.tag==11)
    {
//        [self.tabBarController setSelectedIndex:1];
        HelpMeBagHomeVC *bagDoneView = [[HelpMeBagHomeVC alloc] init];
        [self.navigationController pushViewController:bagDoneView animated:YES];
    }
   
}

- (void)leftSwipe {
    if (self.tabBarController.selectedIndex == 0) {
        //这边根据需求写
        return;
    }
    self.tabBarController.selectedIndex--;
}

- (void)rightSwipe {
    if (self.tabBarController.selectedIndex == self.tabBarController.childViewControllers.count-1) {
        //这边根据需求写
        return;
    }
    self.tabBarController.selectedIndex++;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
   
}

@end
